package com.bs.modules.use.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bs.modules.use.entity.AppComplaintEntity;
import com.bs.modules.use.service.AppComplaintService;
import com.bs.common.utils.PageUtils;
import com.bs.common.utils.R;


/**
 * 投诉
 *
 * @author lichenguang
 * @email 13031069255@163.com
 * @date 2022-04-05 20:38:56
 */
@RestController
@RequestMapping("use/appcomplaint")
@Api(tags = "投诉")
public class AppComplaintController {

  @Autowired
  private AppComplaintService appComplaintService;

  @ApiOperation(value = "列表")
  @GetMapping("/list")
  @RequiresPermissions("use:appcomplaint:list")
  public R list(@RequestParam Map<String, Object> params) {
    PageUtils page = appComplaintService.queryPage(params);


    return R.ok().put("page", page);
  }


  @ApiOperation(value = "详情")
  @GetMapping("/info/{id}")
  @RequiresPermissions("use:appcomplaint:info")
  public R info(@PathVariable("id") Long id) {
    AppComplaintEntity appComplaint = appComplaintService.getById(id);

    return R.ok().put("appComplaint", appComplaint);
  }

  @ApiOperation(value = "保存")
  @PostMapping("/save")
  @RequiresPermissions("use:appcomplaint:save")
  public R save(@RequestBody AppComplaintEntity appComplaint) {
    appComplaintService.save(appComplaint);

    return R.ok();
  }


  @ApiOperation(value = "修改")
  @PostMapping("/update")
  @RequiresPermissions("use:appcomplaint:update")
  public R update(@RequestBody AppComplaintEntity appComplaint) {
    appComplaintService.updateById(appComplaint);

    return R.ok();
  }

  @ApiOperation(value = "删除")
  @PostMapping("/delete")
  @RequiresPermissions("use:appcomplaint:delete")
  public R delete(@RequestBody Long[] ids) {
    appComplaintService.removeByIds(Arrays.asList(ids));

    return R.ok();
  }

  @ApiOperation(value = "修改状态")
  @PostMapping("/updateState")
  public R updateState(@RequestBody AppComplaintEntity appComplaint) {

    appComplaintService.updateState(appComplaint.getId(), appComplaint.getState());

    return R.ok();
  }

}
